package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.CPService;
import com.yixun.qfbao.apidto.GetCPPageReqDto;
import com.yixun.qfbao.apidto.GetCPPageResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.PartnerInfo;
import com.yixun.qfbao.utils.LoginUtils;
import com.yixun.qfbao.vo.GetCPPageReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 客户报备记录
 * 	分页
 * @author JHSong
 *		
 */
@Service("getCPPageHander")
public class GetCPPageHander extends CommonAbstractHander {
	private static Logger logger= LoggerFactory.getLogger(GetCPPageHander.class);
	
	@Autowired
	private CPService cpService;
	@Autowired
	private LoginUtils loginUtils;
	
	@SuppressWarnings("rawtypes")
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		GetCPPageReqVo req = (GetCPPageReqVo)reqDto;
		GetCPPageReqDto reqDto1 = req.getParams();
		BaseResponseDTO<GetCPPageResDto> res = new BaseResponseDTO<GetCPPageResDto>();
		GetCPPageResDto resDto = new GetCPPageResDto();
		PartnerInfo pi = loginUtils.getUser(reqDto1.getUserId());
		if (pi == null) {
			res.setResult(ResultEnum.USER_IS_NULL.getNo());
			res.setErrorMsg("未找到用户信息");
			return res;
		}
		reqDto1.setAccountType(pi.getAccountType());
		reqDto1.setMerchantId(pi.getHigherid());
		Long groupId = reqDto1.getGroupId();
		if(groupId != null) {
			reqDto1.setStoreOrGroupId(groupId);
		}
		try {
			resDto = cpService.getCPPage(reqDto1);
		} catch (Exception e) {
			logger.error("获取报备分页失败, GetCPPageHander error: {}", e);
			resDto.setResultMsg("获取报备分页失败," + e.getMessage());
		}
		res.setResData(resDto);
		res.setResult(resDto.getResult());
		return res;
	}
	
}
